package com.clz.servise;

import com.clz.servise.Impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet("/PageDelete")
public class PageDeleteServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String  uId=request.getParameter("userId");
        int userId=Integer.parseInt(uId);
        UserService userService = new UserServiceImpl();
        //删除用户
        boolean boo=userService.deleteUser(userId);
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out=response.getWriter();
        if (boo) {
            out.println("<script>alert('删除成功！');</script>");
            out.println("<script>window.location.href='/PageServlet';</script>");
        } else {
            out.println("<script>alert('删除失败！');</script>");
            out.println("<script>window.location.href='/PageServlet';</script>");
        }

    }
}
